<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>保险支公司管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="insSubCompBase" title="基本信息" lselected="true">
                <form id="insCompInfo_form">
                    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                        <div class="caption">
                            <span class="title">保险支公司基本信息</span>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">保险公司</div>
                            <div class="field">
                                <input name="compPid" id="compPid" data-value="${insCompInfoVO.compPid}" placeholder="请选择" ltype="combobox" disabled validate="{required:true}">
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>
                        <div class="fieldBox col_33">
                            <div class="label">支公司名称</div>
                            <div class="field">
                                <input name="compNm" id="compNm" type="text" class="ui-textbox" value="${insCompInfoVO.compNm}" validate="{required:true}" readonly>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>

                        <div class="fieldBox col_33">
                            <div class="label">渠道</div>
                            <div class="field">
                                <input name="chnCd" id="chnCd" data-value="${insCompInfoVO.chnCd}" placeholder="请选择" ltype="combobox" validate="{required:true}" readonly>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>

                        <div class="fieldBox col_33">
                            <div class="label">购买方式</div>
                            <div class="field">
                                <input name="buyWayCd" id="buyWayCd" data-value="${insCompInfoVO.buyWayCd}" placeholder="请选择" ltype="combobox" validate="{required:true}" readonly>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>

                        <div class="fieldBox col_33">
                            <div class="label">区域-省份</div>
                            <div class="field">
                                <input name="rgnPrCd" id="rgnPrCd" data-value="${insCompInfoVO.rgnPrCd}" placeholder="请选择" ltype="combobox" validate="{required:true}" readonly>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>

                        <div class="fieldBox col_33">
                            <div class="label">区域-城市</div>
                            <div class="field">
                                <input name="rgnCyCd" id="rgnCyCd" data-value="${insCompInfoVO.rgnCyCd}" placeholder="请选择" ltype="combobox" validate="{required:true}" readonly>
                                <span class="requiredSymbol">*</span>
                            </div>
                        </div>

                        <div class="fieldBox col_100">
                            <div class="label">备注</div>
                            <div class="field" style="width:100%;">
                                <textarea name="compRem" id="compRem" class="ui-textarea l-textarea" cols="65" rows="3" value="${insCompInfoVO.compRem}" style="width:99%;"
                                          validate="{required:false}">${insCompInfoVO.compRem}</textarea>
                            </div>
                        </div>
                        <c:if test="${not empty insCompInfoVO.id}">
                            <div class="fieldBox col_100" id="fileModify">
                                <div class="label">资料</div>
                                <div class="field">
                                    <jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true">
                                        <jsp:param name="pkId" value="${insCompInfoVO.id }"/>
                                        <jsp:param name="tabNm" value="INS_COMP_INFO"/>
                                    </jsp:include>
                                </div>
                            </div>
                        </c:if>

                        <div class="fieldBox col_100">
                            <div class="label">资料上传</div>
                            <div class="field">
                                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                                    <jsp:param name="filePath" value="insCompInfo"/>
                                </jsp:include>
                            </div>
                        </div>
                    </div>
                    <div class="btnsBox">
                        <input name="compLvl" id="compLvl" type="text" style="display: none;" value="2">
                        <input name="compStsCd" id="compStsCd" type="text" style="display: none;" value="10">
                        <span id="saveInsCompInfo_Btn" class="sq-button sq-button-hasicon l-dialog-btn-ok">
                        <i class="sqBtnIco_10"></i>保存</span>
                        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script>
    var pageInApp = {
        flag: true
    };
    var loadedTabs = [];
    var form;
    $(function () {
        var insCompInfoId = "${insCompInfoVO.id}";//主键ID
        var chnCd = "${insCompInfoVO.chnCd}";

        $("#rgnPrCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
            onChangeValue: function (value) {
                if (value) {
                    setCity(value);
                }
            }
        });
        $("#rgnCyCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        //发送请求获取省级区域
        $.ajax({
            type: 'post',
            dataType: 'json',
            url: '<%=path%>/system/sysRegion/getProvinceRegion.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var seltPr = liger.get("rgnPrCd");
                    seltPr.setData(msg.data);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

        $("#compPid").ligerComboBox({
            valueField: 'id',
            textField: 'compNm'
        });

        $("#buyWayCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        $("#chnCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });

        form = $("#insCompInfo_form").ligerForm({
            validate: true
        });
        liger.get("chnCd").setData(${chnCdList});
        liger.get("buyWayCd").setData(${buyWayCdList});
        liger.get("compPid").setData(${insCompList});

        liger.get('compPid').setDisabled(true);
        liger.get('buyWayCd').setDisabled(true);
        liger.get('chnCd').setDisabled(true);
        liger.get('rgnPrCd').setDisabled(true);
        liger.get('rgnCyCd').setDisabled(true);

        /*保存*/
        $("#saveInsCompInfo_Btn").click(function (event) {
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            chnCd = data["chnCd"];
            data["rgnPrNm"] = $("#rgnPrCd").val();
            data["rgnCyNm"] = $("#rgnCyCd").val();
            var fileParams = getUploadResultParams();//获取附件上传的信息
            data["fileParams"] = JSON.stringify(fileParams);

            $.ligerDialog.hide();
            var _url;
            if (insCompInfoId == '') {//新增
                _url = '<%=path%>/insurance/insCompInfo/add.do';
            } else {//修改
                _url = '<%=path%>/insurance/insCompInfo/modify.do?id=' + insCompInfoId;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: _url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        pageInApp.flag = false;
                        //回调刷新列表
                        var callback = frameElement.W2W.callback;
                        callback();
                        if (!insCompInfoId) {
                            insCompInfoId = msg.data;
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            form.setData({  //重置select等特殊表单
                "buyWayCd": " ",
                "compPid": " "
            });
        });
        
    });

    function setCity(value) {
        var seltPr = liger.get("rgnPrCd");
        var rgnCd = seltPr.findValueByText(value);
        if (!rgnCd) {
            return;
        }
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {rgnCd: rgnCd},
            url: '<%=path%>/system/sysRegion/getRegionByRgnCd.do',
            success: function (msg) {
                if (msg.success == 1) {
                    var seltCy = liger.get("rgnCyCd");
                    if (msg.data) {
                        seltCy.setData(msg.data);
                        seltCy.selectValue(msg.data[0].key)
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function getUlFileRecDelColumn(){

    }

</script>
</body>
</html>
